package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.FileUploadService;
import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@Tag(name = "上传管理接口")
@RestController
@RequestMapping("api/album")
public class FileUploadApiController {
    @Autowired
    private FileUploadService uploadService;

    @Operation(summary = "文件上传")
    @PostMapping("/fileUpload")
    public Result<String> fileUpload (@Parameter(name ="file") MultipartFile file) throws Exception {
        String url = uploadService.fileUpload(file);
        return Result.ok(url);
    }


    @Operation(summary = "上传声音")
    @PostMapping("/trackInfo/uploadTrack")
    public Result<Map<String,String>> uploadTrack(@RequestParam("file") MultipartFile file){
        Map<String,String> mediaInfo = uploadService.uploadTrack(file);
        return Result.ok(mediaInfo);
    }
}
